import { isUrl } from 'utils/utils';

const menuData = [
  {
    name: '工作台',
    icon: 'dashboard',
    path: 'dashboard',
  },
  {
    name: '课程级别',
    icon: 'book',
    path: 'course',
  },
  {
    name: '绘本抢先看',
    icon: 'book',
    path: 'preview',
  },
  {
    name: '知识点',
    icon: 'book',
    path: 'knowledge',
  },
  {
    name: '辅助词',
    icon: 'book',
    path: 'assist',
  },
  {
    name: '评测',
    icon: 'book',
    path: 'review',
    children: [
      {
        name: '等级',
        icon: 'user-add',
        path: 'level',
      },
      {
        name: '单词库',
        icon: 'file-word',
        path: 'word',
      },
    ],
  },
  {
    name: '附件',
    icon: 'file',
    path: 'attachment',
  },
  {
    name: '标签',
    icon: 'tags',
    path: 'tag',
  },
  {
    name: ' 测试模板',
    icon: 'book',
    path: 'test/tpl',
  },
];

// const base = process.env.NODE_ENV === 'production' ? '/course/' : '/course-test/';
const base = '/';
function formatter(data: any[], parentPath = base, parentAuthority?: string) {
  return data.map((item: Record<string, any>) => {
    let { path } = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
    const result: Record<string, any> = {
      ...item,
      path,
      authority: item.authority || parentAuthority,
    };
    if (item.children) {
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
    }
    return result;
  });
}

export const getMenuData = () => formatter(menuData);
